library(flextable)
library(DiagrammeR)
library(lavaan)
library(tidyverse)At this point, I will construct an overall mediation model.
Let’s take a look at the boxes-and-arrows.
grViz("
digraph mediation {
graph [overlap = true,
rankdir = LR,
bgcolor = '#222222']
node [shape = box,
color = wheat,
fontcolor = wheat]
edge [color = wheat,
fontcolor = wheat]
disclosure->'affective trust' [label = <a<SUB>aff</SUB>>]
disclosure->liking [label = 'c′']
disclosure->'cognitive trust' [label = <a<SUB>cog</SUB>>]
'affective trust'->liking [label = <b<SUB>aff</SUB>>]
'cognitive trust'->liking [label = <b<SUB>cog</SUB>>]
}
")Now, I’ll build the actual data model. My understanding is that I can follow the classic procedure, but control for cognitive trust when testing affective trust—and vice versa.
data <- readRDS(file.path("..", "data", "hq-data.rds"))
formatAsTable <- readRDS("format.rds")model.aff <- "# measurement model
aff =~ aff1 + aff2 + aff3 + aff4
lik =~ lik1 + lik2 + lik3.r + lik4.r
# structural model
aff ~ affa*disclose
lik ~ affb*aff
lik ~ cprime*disclose
ind_fx := affa*affb
tot_fx := affa*affb + cprime"
fit.aff <- model.aff %>%
sem(data)
fit.aff %>%
parameterEstimates %>%
filter(op %in% c("~", ":=")) %>%
formatAsTablelhs | op | rhs | label | est | se | z | pvalue | ci.lower | ci.upper |
aff | ~ | disclose | affa | 0.66 | 0.09 | 7.37 | 0.00 | 0.49 | 0.84 |
lik | ~ | aff | affb | 0.90 | 0.04 | 21.06 | 0.00 | 0.81 | 0.98 |
lik | ~ | disclose | cprime | -0.06 | 0.09 | -0.63 | 0.53 | -0.24 | 0.12 |
ind_fx | := | affa*affb | ind_fx | 0.59 | 0.08 | 7.32 | 0.00 | 0.43 | 0.75 |
tot_fx | := | affa*affb+cprime | tot_fx | 0.53 | 0.11 | 4.72 | 0.00 | 0.31 | 0.76 |
\(c\prime\) goes to zero…looks like full mediation!
model.cog <- "# measurement model
cog =~ cog1 + cog2 + cog3
lik =~ lik1 + lik2 + lik3.r + lik4.r
# structural model
cog ~ coga*disclose
lik ~ cogb*cog
lik ~ cprime*disclose
ind_fx := coga*cogb
tot_fx := coga*cogb + cprime"
fit.cog <- model.cog %>%
sem(data)
fit.cog %>%
parameterEstimates %>%
filter(op %in% c("~", ":=")) %>%
formatAsTablelhs | op | rhs | label | est | se | z | pvalue | ci.lower | ci.upper |
cog | ~ | disclose | coga | 0.33 | 0.11 | 2.94 | 0.00 | 0.11 | 0.55 |
lik | ~ | cog | cogb | 0.73 | 0.05 | 15.93 | 0.00 | 0.64 | 0.82 |
lik | ~ | disclose | cprime | 0.25 | 0.09 | 2.79 | 0.01 | 0.07 | 0.42 |
ind_fx | := | coga*cogb | ind_fx | 0.24 | 0.08 | 2.89 | 0.00 | 0.08 | 0.40 |
tot_fx | := | coga*cogb+cprime | tot_fx | 0.49 | 0.10 | 4.68 | 0.00 | 0.28 | 0.69 |
\(c\prime\) doesn’t go to zero, so we can’t say we have full mediation. But \(a_{cog}\) and \(b_{cog}\) are significant, so I think that means partial mediation.
model.tru <- "# measurement model
aff =~ aff1 + aff2 + aff3 + aff4
cog =~ cog1 + cog2 + cog3
lik =~ lik1 + lik2 + lik3.r + lik4.r
# structural model
aff ~ affa*disclose
cog ~ coga*disclose
lik ~ affb*aff + cogb*cog
lik ~ cprime*disclose
ind_fx := affa*affb + coga*cogb
tot_fx := affa*affb + coga*cogb + cprime"
fit.tru <- model.tru %>%
sem(data)
fit.tru %>%
parameterEstimates %>%
filter(op %in% c("~", ":=")) %>%
formatAsTablelhs | op | rhs | label | est | se | z | pvalue | ci.lower | ci.upper |
aff | ~ | disclose | affa | 0.66 | 0.09 | 7.37 | 0.00 | 0.49 | 0.84 |
cog | ~ | disclose | coga | 0.33 | 0.11 | 2.93 | 0.00 | 0.11 | 0.55 |
lik | ~ | aff | affb | 0.88 | 0.04 | 20.94 | 0.00 | 0.80 | 0.96 |
lik | ~ | cog | cogb | 0.78 | 0.05 | 16.51 | 0.00 | 0.69 | 0.87 |
lik | ~ | disclose | cprime | -0.31 | 0.11 | -2.79 | 0.01 | -0.53 | -0.09 |
ind_fx | := | affa*affb+coga*cogb | ind_fx | 0.84 | 0.15 | 5.63 | 0.00 | 0.55 | 1.13 |
tot_fx | := | affa*affb+coga*cogb+cprime | tot_fx | 0.53 | 0.11 | 4.72 | 0.00 | 0.31 | 0.74 |
That’s interesting! Trust doesn’t fully mediate the effect of disclosure on liking—it inconsistently mediates it. That is, disclosure has a significantly negative effect on liking when controlling for trust.
I’m not sure what would explain that. Maybe something like my hypothesis (that disclosure calls attention to negative aspects of ADHD) is true, but cognitive trust was the wrong construct to use. Or it could be that disclosure makes someone trustworthy, but otherwise makes them look bad (annoying, poor social skills, oversharing, that kind of thing). There’s no way to know for sure without more studies.
Also, as predicted, affective trust is a stronger mediator than cognitive trust.
Output document:
options(knitr.duplicate.label = "allow")
rmarkdown::render("mediation.Rmd",
output_dir = file.path("..", "github", "thesis"))